package com.app.dao.controller;


import com.app.dao.entity.Record;
import com.app.dao.service.RecordService;
import com.app.model.dto.PageDTO;
import com.app.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 记录表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2023
 */
@RestController
@RequestMapping("/record")
@RequiredArgsConstructor
public class RecordController {

    private final RecordService iRecordService;


    @PostMapping("page")
    @ApiOperation("记录表分页")
    public Result<Page<Record>> page(@RequestBody PageDTO pageDTO) {
        return Result.ok(iRecordService.page(pageDTO));
    }

    @GetMapping("listAll")
    @ApiOperation("记录表列表")
    public Result<List<Record>> listAll() {
        return Result.ok(iRecordService.listAll());
    }

    @GetMapping("getById/{id}")
    @ApiOperation("记录表详情")
    public Result<Record> getRecordById(@PathVariable("id") String id) {
        return Result.ok(iRecordService.getRecordById(id));
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation("记录表删除")
    public Result<Boolean> deleteRecordById(@PathVariable("id") String id) {
        return Result.ok(iRecordService.deleteRecordById(id)).setMsg("删除成功").setShowMsg(true);
    }

    @PostMapping("add")
    @ApiOperation("记录表新增")
    public Result<Boolean> addRecord(@RequestBody Record obj) {
        return Result.ok(iRecordService.addRecord(obj)).setMsg("新增成功").setShowMsg(true);
    }


    @PutMapping("updateById")
    @ApiOperation("记录表更新")
    public Result<Boolean> updateRecordById(@RequestBody Record obj) {
        return Result.ok(iRecordService.updateRecordById(obj)).setMsg("更新成功").setShowMsg(true);
    }

}
